package main;

public class Variable{
	
	private String type, name;
	private boolean isFinal, value=false;
	
	public Variable (boolean isFinal, String type,  String name) {
		this.isFinal=isFinal;
		this.type=type;
		this.name=name;
	}
	
	public Variable (boolean isFinal, String type,  String name, String value) throws compilationException {
		this.isFinal=isFinal;
		this.type=type;
		this.name=name;
		if (value!=null) {
			setValue(value);
		}
		else if (isFinal)
			throw new compilationException("Error 5: Final must has value");
	    
	}
	
	public String getName () {
		return this.name;
	}
	
	public String getType () {
		return this.type;
	}
	
	public boolean getIsFinal () {
		return this.isFinal;
	}
	
	public boolean getValue () {
		return this.value;
	}
	
	public void setValue (String value) throws compilationException {
		if (isFinal && this.value==true)
			throw new compilationException("Error 5: Final can't be modified");
		this.value=true;
		
		CheckType.isValueMuchType (value, this.type);
		
	}
	
	
}
